package gx.illnessRecord.controller;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import gx.JsonResult;
import gx.entrance.entity.User;
import gx.illnessRecord.entity.IllnessRecord;
import gx.illnessRecord.service.IllnessRecordService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("illnessRecord")
@Api(value = "IllnessRecord",description = "入口 查询病历记录列表 ")
public class illnessRecordController {

	@Autowired
	private IllnessRecordService illnessRecordService;
	
	// 创建线程安全的Map
	static Map<String, IllnessRecord> illnessRecordMap = Collections.synchronizedMap(new HashMap<String, IllnessRecord>());
	
	// log4j日志输出
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	/**
	 * 查询病历记录列表
	 * @return
	 */
	@ApiOperation(value="查询病历记录列表", notes="查询病历记录列表")
	@RequestMapping(value = "illnessRecords", method = RequestMethod.POST)
	public ResponseEntity<JsonResult> getIllnessRecordList (){
		JsonResult r = new JsonResult();
		try {
			List<IllnessRecord> illnessRecords = illnessRecordService.getIllnessRecordList();
			r.setResult(illnessRecords);
			r.setStatus("ok");
		} catch (Exception e) {
			r.setResult(e.getClass().getName() + ":" + e.getMessage());
			r.setStatus("error");
			e.printStackTrace();
		}
		return ResponseEntity.ok(r);
	}
	
	/**
	 * 添加病历记录,(确保每天添加)
	 * @return
	 */
	@ApiOperation(value="新增病历记录", notes="新增病历记录")
	@ApiImplicitParam(name = "addIllnessRecord", value = "新增用户实体illnessRecord", required = true, dataType = "IllnessRecord")
	@RequestMapping(value = "addIllnessRecord", method = RequestMethod.POST)
	public ResponseEntity<JsonResult> add (IllnessRecord illnessRecord){
		JsonResult r = new JsonResult();
		try {
			illnessRecordService.add(illnessRecord);
			illnessRecordMap.put(illnessRecord.getId(), illnessRecord);
			r.setResult(illnessRecord.getId());
			r.setStatus("ok");
		} catch (Exception e) {
			r.setResult(e.getClass().getName() + ":" + e.getMessage());
			r.setStatus("error");

			e.printStackTrace();
		}
		return ResponseEntity.ok(r);
	}

	/**
	 * 判断此次时间是否有上传记录
	 * @return
	 */
	@ApiOperation(value="获取此次时间是否含有记录", notes="获取此次时间是否含有记录")
	@ApiImplicitParam(name = "nowTime", value = "",required = true, dataType = "String", paramType = "path")
	@RequestMapping(value = "queryNowTimeHasRecord", method = RequestMethod.POST)
	public ResponseEntity<JsonResult> queryNowTimeHasRecord (String nowTime){
		JsonResult r = new JsonResult();
		try {
			IllnessRecord illnessRecord = illnessRecordService.queryNowTimeHasRecord(nowTime);
			r.setResult(illnessRecord);
			r.setStatus("ok");
		} catch (Exception e) {
			r.setResult(e.getClass().getName() + ":" + e.getMessage());
			r.setStatus("error");

			e.printStackTrace();
		}
		return ResponseEntity.ok(r);
	}
	
	/**
	 * 
		{	
			"uuid": "swagger",
			"login_name": "swagger",
			"login_password": "swagger111",
			"nick_name": "nick_name",
			"status": 1,
			"add_time": "add_time",
			"remark": "remark"
		}
	 */
}
